package Solution101_200.problem108.ConvertSortedArraytoBinarySearchTree;

import common.TreeNode;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/07/11 17:00
 */
public class Solution {

    public TreeNode sortedArrayToBST(int[] nums) {
        return buildBST(nums,0,nums.length-1);
    }
    private TreeNode buildBST(int[] nums, int start,int end) {
        if (start > end) {
            return null;
        }
        int mid = (start + end) / 2;
        int value = nums[mid];
        TreeNode root = new TreeNode(value);
        root.left = buildBST(nums, start, mid - 1);
        root.right = buildBST(nums, mid + 1, end);
        return root;
    }
}
